package com.eastfair.venuebooking.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.venuebooking.dto.ExhibitionCustomerPageQuery;
import com.eastfair.venuebooking.dto.ExhibitionCustomerSaveDTO;
import com.eastfair.venuebooking.dto.ExhibitionCustomerUpdateDTO;
import com.eastfair.venuebooking.entity.ExhibitionCustomer;
import com.eastfair.venuebooking.service.ExhibitionCustomerService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 展会客户关系
 * </p>
 *
 * @author dqq
 * @date 2023-04-03
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/exhibitionCustomer")
@Api(value = "ExhibitionCustomer", tags = "展会客户关系")
@PreAuth(replace = "venuebooking:exhibitionCustomer:")
public class ExhibitionCustomerController extends SuperController<ExhibitionCustomerService, Long, ExhibitionCustomer, ExhibitionCustomerPageQuery, ExhibitionCustomerSaveDTO, ExhibitionCustomerUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<ExhibitionCustomer> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ExhibitionCustomer> exhibitionCustomerList = list
                .stream()
                .map((map) -> ExhibitionCustomer.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(exhibitionCustomerList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ExhibitionCustomerPageQuery> params) {
        ExhibitionCustomerPageQuery pageQuery = params.getModel();
    }

}
